import acroMLResources from "./acroML.Resources.mjs";
import acroMLUtils from "./acroML.Utils.mjs";
import AcroMLDD from "./acroML.DD.mjs";
let onDisplayValueLostEvents=[];
class AcroMLEngine{
    async readDD(ddFile){
    }
    getDisplayValue(DDKey,LCID,SeqNo='0'){
        if (!this.dd) return DDKey;
        if (LCID==undefined) throw new Error('LCID is not provided.');
        let isFound={value:false};
        let text=this.dd.getDisplayValue(DDKey,LCID,SeqNo,isFound);
        //console.log(DDKey,isFound);
        if (!isFound.value){
            for(let i=0;i<onDisplayValueLostEvents.length;i++){
                onDisplayValueLostEvents[i](DDKey,LCID,SeqNo);
            }
        }
        return text;
    }
    async start(ops){
        //console.log(ops);
        let self=this;
        self.ddFile=ops.ddFile;
        let ddContentStr=ops.ddContentStr;
        if (!ddContentStr){
          let ddContent=await self.readDD(ops.ddFile);
          ddContentStr=ddContent.str;
        }
        self.ddClass=ops.ddClass;
        self.dd=AcroMLEngine.buildDD(ops.ddFile,ddContentStr,ops.ddClass);
    }
    static buildDD(ddFile,ddStr,ddClass){
        //console.log(content);
        if (!ddClass){
          let ddInfo=AcroMLDD.getDDByFileExt(ddFile);
          //console.log(DDClass);
          if (!ddInfo) throw new Error(acroMLUtils.printf(acroMLResources.S_UnknownFileExt,ddFile));
          ddClass=ddInfo.class;
        }
        let dd=new ddClass();
        dd.content=ddStr;
        dd.buildDD();
        return dd;
    }
    static onDisplayValueLost(cb){
        onDisplayValueLostEvents.push(cb);
    }
    static init(ops){
        AcroMLEngine.instance=new ops.engineClass();
        return AcroMLEngine.instance.start(ops);
    }
    static instance=null;
    static onSwitchLanguage=null;
}
export default AcroMLEngine;
export {AcroMLEngine as Engine};